<?php
/**
 * 应用管理
 *
 * @copyright   Copyright 2011, Richie
 * @author      Richie <richbossman@163.com>
 * @package     SMS
 * @link        http://www.letphp.com
 * 
 * $Id: AppsAction.class.php 53 2011-03-25 14:02:39Z 442767452@qq.com $
 */
class AppsAction extends SystemAction {
	
	//按钮
	function _button_apps_index(){
		return array('add');
	}
	
	function _button_apps_add(){
		//按钮
		return array('index');
	}
	
	function _button_apps_edit(){
		return array('index', 'add');
	}
	//列表json
	function lst(){
		$result = array();
		$result['total'] = M('apps')->count();
		$result['rows'] = M('apps')->field('app_id, app_name, app_title, sort, status, add_time, remark')
				->page($this->datagrid['page'])
				->limit($this->datagrid['rows'])
				->order($this->datagrid['sort'].' '.$this->datagrid['order'])
				->findAll();
		foreach ($result['rows'] as $key=>$row){
			$result['rows'][$key]['add_time'] = date('Y-m-d H:i', $row['add_time']);
		}
		$this->ajaxReturn('', $result);
	}
	
	//删除应用
	function remove(){
		$app_id = isset($_POST['app_id']) ? trim($_POST['app_id']) : 0;
		$node = M('node')->where('app_id='.$app_id)->field('node_id')->find();
		if($node){
			$this->ajaxReturn(L('do_not_delete_apps'), array(), 0);
		}
		M('apps')->where('app_id='.$app_id)->delete();
		$this->ajaxReturn('');
	}
	
	//应用列表
	public function apps_list($app_id=0){
		$apps = M('apps')->field('app_id,app_name,app_title')->order('sort ASC, app_id DESC')->findAll();
		foreach($apps as $key=>$app){
			$apps[$key]['selected'] = ($app_id == $app['app_id']) ? true : false;
		}
		return $apps;
	}
}
?>